package net.sxjr.common;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author ：cuixc
 * @date ：Created in 2020/10/20 19:56
 * @description：servlet 工具
 * @modified By：
 */
public class ServletUtil {


    public static ServletRequestAttributes getRequestAttributes() {

        return (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    }

    public static HttpServletRequest getRequest() {
        return getRequestAttributes().getRequest();
    }

    public static HttpSession getSession() {
        String token = getRequestAttributes().getRequest().getHeader("token");
        return getRequestAttributes().getRequest().getSession().getSessionContext().getSession(token);
    }

    public static String  getToken() {
        return getRequest().getHeader("token");
    }

}
